import socket

#创建socket对象
socket_server = socket.socket()
#指定ip和端口
socket_server.bind(('127.0.0.1', 8888))
# 监听端口
socket_server.listen(1)

# result: tuple = socket_server.accept()
# conn = result[0]
# addr = result[1]

# 阻塞连接等待客户端连接
conn,addr = socket_server.accept()

print(f"接收到客户端的连接：{conn}，{addr}")

# 接受客户端信息
data: str = conn.recv(1024).decode("utf-8")

print(f"客户端发来消息：{data}")

msg = input("请输入你要和客户端回复的消息：")
conn.send(msg.encode("utf-8"))
conn.close()
socket_server.close()